<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<script type="text/javascript" src="<%=basePath %>/bootstrap/js/jquery.js"></script>
	<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>	
	<script type="text/javascript" src="https://raw.github.com/HPNeo/gmaps/master/gmaps.js"></script>
	<script type="text/javascript" src="<%=basePath %>/bootstrap/js/bootstrap.min.js"></script>
	<link rel="stylesheet" href="<%=basePath %>/bootstrap/css/bootstrap.min.css" />
	<style type="text/css">
		body{
			background-image:url("<%=basePath%>/bootstrap/img/5.jpg");
			 background-attachment :local; 
			 background-size: cover;
		}
		.container{
			margin-left:50px;
		}
		.container .nav{
			margin-left:120px;
		}
		.span3{
			background-image:url("<%=basePath%>/bootstrap/img/5.jpg");
		}
		.container-fluid{
			margin-top:70px;
			margin-left:-20px;
		}
		#navleft{
			font-size:18px;
		}
		#aleft{
			color:black;
		}
		#aleft:hover{
			color:blue;
		}
		.pagerhader,.reqiredtable {
			background-image:url("<%=basePath%>/bootstrap/img/5.jpg");
			border-bottom: 1px solid #DADEE5;
			font-size: 18px;
			padding: 15px 30px;
			position: relative;
		}
		.othertable{
			border-bottom: 1px solid #DADEE5;
			font-size: 18px;
			padding: 15px 30px;
			position: relative;
		}
		.pagecontent .time {
			width: 50px;
		}
		td {
			padding: 0.8em;
		}
		
		.event{
			background-color:blue;
		}
		.winchance,.success{
			background-color:green;
		}
		.fail,.losttask{
			background-color:red;
		}
		.chance,.followchance{
			background-color:black;
		}
		.task{
			background-color:orange;
		}
		.today{
			background-color: #FFCC00;
		}
		.box {
			background-color: #FFFFFF;
			margin-bottom: 10px;
			padding-bottom: 10px;
			width:250px;
		}
		.task1{
			margin-left:20px;
			font-size:16px;
		}
		strong, th, thead td, h1, h2, h3, h4, h5, h6 {
			font-weight: bold;
		}
		#anpai{
			width:250px;
			height:40px;
			background-color: #F0F5F8;
		}
		strong{
			font-size:16px;
		}
		#select1,#select2{
			width:80px;
		}
	</style>
</head>
<body>
	<!--导航-->
	   	   <div id="navbar-example" class="navbar navbar-fixed-top">
            <div class="navbar-inner">
              <div class="container" style="width: auto; height:10px">
                <a class="brand" href="#">CRM</a>
                <ul class="nav">
					<li class="">
						 <form id="searchForm" class="navbar-search pull-left" action="http://www.google.com.hk/search" method="get">
								<input type="text" id="search" class="search-query span5" name="q" autocomplete="off" placeholder="Google Search"/>
								<script>
									$(document).ready(function(){
										$("#search").keydown(function(){
											if(event.keyCode == 13) {
												$("searchForm").submit();
											}

										});

									});
								</script>
							</form>
					  </li>
					  <li class="">
						<a href="">用户名：${sessionScope.user.username }</a>
					  </li>
                  <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#menu1">
							账号&设置
							<b class="caret"></b>
						</a>
                    <ul class="dropdown-menu">
						  <li><a href="users.action">我的信息</a></li>
						  <li><a href="groups.action">小组成员</a></li>
						  <script type="text/javascript">
							$(document).ready(function(){
								$(".dropdown-toggle").dropdown();
							});
						 </script>
						</ul>
					</li>
					  <li class="">
						<a href="index.action">安全退出</a>
					  </li>
                </ul>
              </div>
            </div>
          </div>
		  <script type="text/javascript">
			$(document).ready(function(){
				$(".dropdown-toggle").dropdown();
			});
		  </script>

		  <!--左遍的内容-->
		<div class="container-fluid">
		  <div class="row-fluid">
			<div class="span3" style="background-color: #F0F5F8;border: 1px solid #DADEE5;width:170px;height:240px;padding-top:20px;margin-left:40px;">
				<div id="left">
					<ul class="nav nav-list" id="navleft">
					  <li>
						<a href="findAllMessage.action" id="aleft">
						   <img src="<%=basePath%>/bootstrap/img/22.png"/>
							最新动态
						</a>
					  </li>
					  <li>
						<a href="contacts.action" id="aleft">
						 <img src="<%=basePath%>/bootstrap/img/18.png"/>
							联系人
						</a>
					  </li>
					  <li>
						<a href="task.action" id="aleft">
						  <img src="<%=basePath%>/bootstrap/img/20.png"/>
							日程安排
						</a>
					  </li>
					  <li>
						<a href="deal.action" id="aleft">
						 <img src="<%=basePath%>/bootstrap/img/19.png"/>
							业务机会
						</a>
					  </li>
					  <li class="search">
						<a href="search.action" id="aleft">
							<img src="<%=basePath%>/bootstrap/img/21.png"/>
							搜索
						</a>
						</li>
					</ul>
				</div>
			</div>
			<!--中心内容-->
			<div class="span6" style="border:1px solid #D7D7D7;background-color:white;width:700px">
			<div class="pagerhader">
				修改用户
			</div>
			<c:if test="${param.code=='1008' }">
			 	<div style="color:red;width:100px;height:20px;margin-left:auto;margin-right:auto;margin-top:20px;">
			 		修改失败
			 	</div>
			</c:if>
				<form action="editcontacts.action" method="post" id="myform">
					<div class="reqiredtable">
						<div class="control-group">
						  <label class="control-label" for="input01">姓名</label>
						   <div class="controls">
						    <input type="hidden" name="cid" value="${requestScope.c.id }"/>
						   <%--  <input type="hidden" name="uid" value="${sessionScope.user.id }"/> --%>
							<input type="text" id="username" class="text" size="30" name="name" value="${c.name }"/>
						  </div>
						   <label class="control-label" for="input01">公司</label>
						   <div class="controls">
							<!-- <input type="text" id="company" class="text" size="30" name="contacts.companyname"/> -->
							<select name="companyname" id="company">
								<c:forEach items="${clist }" var="con"> 
									<option value="${con.companyname }">${con.companyname }</option>
								 </c:forEach> 
							</select>
							<br/>
							<span style="color:red;font-size:12px;">如果不存在所要填入的公司名称，请先去添加一个新公司</span>
							 </div>
						   <label class="control-label" for="input01">微博</label>
						   <div class="controls">
							<select name="weibotype" size="1" style="width:50px;">
								<option value="http://t.qq.com/">qq</option>
								<option value="http://weibo.com/">新浪</option>
							</select>
							<input type="text" id="job" name="weibo"/>
							</div>
							<label class="control-label" for="input01">地址</label>
						   <div class="controls">
							<input type="text" name="address" id="address" value="${address }"/><br/>
							<input type="button" value="显示地图" id="btnmap" />
							<div id="map" style="width:650px;height:200px">   
							
							</div>
						  </div>
							<span id="error"></span>
					</div>
				</div>
					<div class="othertable">
						<div class="control-group">
						  		<label class="control-label" for="input01">电话</label>
						   <div class="controls" id="controls1">
						   <c:forEach items="${c.telSet }" var="t">
							<input type="text" name="tel" class="text" size="30" value="${t.tel }"/>
							<select name="type">
								<option value="${t.type }">${t.type }</option>
								<option value="work">work</option>
								<option value="home">home</option>
							</select>
							<input type="button" value="+" id="more1"/><br/>
							</c:forEach>
						  </div>
						   <label class="control-label" for="input01">邮箱</label>
						   <div class="controls" id="controls2">
							<c:forEach items="${c.mailSet }" var="m">
								<input type="text" name="mail" value="${m.mail }"/><input type="button" value="+" id="more2"/><br/>
							</c:forEach>
						  </div>
						   <label class="control-label" for="input01">IM</label>
						   <div class="controls" id="controls3">
							<c:forEach items="${c.imSet }" var="im">
								<input type="text" name="im" value="${im.im }"/><input type="button" value="+" id="more3"/><br/>
							</c:forEach>
						  </div>
						   <label class="control-label" for="input01">网站</label>
						   <div class="controls" id="controls4">
							<c:forEach items="${c.websiteSet }" var="w">
								<input type="text" name="website" value="${w.website }"/><input type="button" value="+" id="more4"/><br/>
							</c:forEach>
						  </div>
						   <label class="control-label" for="input01"><strong>背景信息(简介，如何认识的等)</strong></label>
						   <div class="controls">
							<textarea name="content">${c.content }</textarea>
						  </div>
						   <label class="control-label" for="input01"><strong>谁可以看见这个联系人</strong></label>
						   <div class="controls">
						   <%-- <input type="radio" name="view" value="all" checked="checked"/>所有人<br/>
							<input type="radio" name="view" value="me"/>只有我能看见<br/>
							<input type="radio" name="view" id="radio1" value="group"/>
							选择一个组<!--需要写个下拉框-->
							<select name="g" id="select1"><!--提交值得名称-->
							<!--循环-->
								<c:forEach items="${uglist }" var="ug">
									<option value="${ug.id }">${ug.groupname }</option>
								</c:forEach>
							</select>
							<br/>
							<input type="radio" name="view" value="use" id="radio2"/>
							选择用户<!--需要写个下拉框-->
							<select name="u" id="select2">
							<!--循环-->
								<c:forEach items="${ulist }" var="user">
									<option value="${user.id }">${user.username }</option>
								</c:forEach>
							</select> --%>
							<c:choose>
								<c:when test="${c.view.split(',')[0]=='all' }">
									<input type="radio" name="view" value="all" checked="checked"/>所有人<br/>
									<input type="radio" name="view" value="me"/>只有我能看见<br/>
									<input type="radio" name="view" id="radio1" value="group"/>
									选择一个组<!--需要写个下拉框-->
									<select name="g" id="select1"><!--提交值得名称-->
									<!--循环-->
										<c:forEach items="${uglist }" var="ug">
											<option value="${ug.id }">${ug.groupname }</option>
										</c:forEach>
									</select>
									<br/>
									<input type="radio" name="view" value="use" id="radio2"/>
									选择用户<!--需要写个下拉框-->
									<select name="u" id="select2">
									<!--循环-->
										<c:forEach items="${ulist }" var="u">
											<option value="${u.id }">${u.username }</option>
										</c:forEach>
									</select>
								</c:when>
							
							</c:choose>
							<c:choose>
								<c:when test="${c.view.split(',')[0]=='me' }">
									<input type="radio" name="view" value="all"/>所有人<br/>
									<input type="radio" name="view" value="me" checked="checked"/>只有我能看见<br/>
									<input type="radio" name="view" id="radio1" value="group"/>
									选择一个组<!--需要写个下拉框-->
									<select name="g" id="select1"><!--提交值得名称-->
									<!--循环-->
										<c:forEach items="${uglist }" var="ug">
											<option value="${ug.id }">${ug.groupname }</option>
										</c:forEach>
									</select>
									<br/>
									<input type="radio" name="view" value="use" id="radio2"/>
									选择用户<!--需要写个下拉框-->
									<select name="u" id="select2">
									<!--循环-->
										<c:forEach items="${ulist }" var="u">
											<option value="${u.id }">${u.username }</option>
										</c:forEach>
									</select>
								</c:when>
							</c:choose>
							<c:choose>
								<c:when test="${c.view.split(',')[0]=='group' }">
									<input type="radio" name="view" value="all"/>所有人<br/>
									<input type="radio" name="view" value="me"/>只有我能看见<br/>
									<input type="radio" name="view" id="radio1" value="group" checked="checked"/>
									选择一个组<!--需要写个下拉框-->
									<select name="g" id="select1"><!--提交值得名称-->
									<!--循环-->
										<option value="${c.view.split(',')[1] }">${group.groupname }</option>
										<c:forEach items="${uglist }" var="ug">
											<option value="${ug.id }">${ug.groupname }</option>
										</c:forEach>
									</select>
									<br/>
									<input type="radio" name="view" value="use" id="radio2"/>
									选择用户<!--需要写个下拉框-->
									<select name="u" id="select2">
									<!--循环-->
										<c:forEach items="${ulist }" var="u">
											<option value="${u.id }">${u.username }</option>
										</c:forEach>
									</select>
								</c:when>
							</c:choose>
							<c:choose>
								<c:when test="${c.view.split(',')[0]=='use' }">
									<input type="radio" name="view" value="all"/>所有人<br/>
									<input type="radio" name="view" value="me"/>只有我能看见<br/>
									<input type="radio" name="view" id="radio1" value="group"/>
									选择一个组<!--需要写个下拉框-->
									<select name="g" id="select1"><!--提交值得名称-->
									<!--循环-->
										
										<c:forEach items="${uglist }" var="ug">
											<option value="${ug.id }">${ug.groupname }</option>
										</c:forEach>
									</select>
									<br/>
									<input type="radio" name="view" value="use" id="radio2"  checked="checked"/>
									选择用户<!--需要写个下拉框-->
									<select name="u" id="select2">
									<!--循环-->
										<option value="${c.view.split(',')[1] }">${user.username }</option>
										<c:forEach items="${ulist }" var="u">
											<c:if test="${c.view.split(',')[1] != u.id }">
												<option value="${u.id }">${u.username }</option>
											</c:if>
										</c:forEach>
									</select>
								</c:when>
							</c:choose>
						  </div>
						  <input type="button" class="btn btn-primary" value="保存并添加这个联系人" id="btn"/> 或者 <input type="reset" value="重置"/> 
						</div>
					</div>
				</form>
			</div>	
		</div>
	</div>
	<script type="text/javascript">
		var map;
		$(document).ready(function(){
			 map = new GMaps({					
				div: '#map',					
				lat: 35.2193612,					
				lng: 113.2482923 			
			});			
			$("#btnmap").click(function(){				
				GMaps.geocode({				  
				address: $('#address').val(),				  
				callback: function(results, status) {					
				if (status == 'OK') {					 
					 var latlng = results[0].geometry.location;					  
					 map.setCenter(latlng.lat(), latlng.lng());					  
					 map.addMarker({						
					 lat: latlng.lat(),						
					 lng: latlng.lng()					 
					  });					
			  	}				  
			  }				
			 });			
			}); 
			
				
			$("#more1").click(function(){
				$("#controls1").append($("<input type='text' name='tel' class='text' size='30'/>"+"<select name='type'><option value='work'>work</option><option value='home'>home</option></select><br/>"));
			});
			$("#more2").click(function(){
				$("#controls2").append($("<input type='text' name='mail' class='text' size='30'/><br/>"));
			});
			$("#more3").click(function(){
				$("#controls3").append($("<input type='text' name='im' class='text' size='30'/><br/>"));
			});
			$("#more4").click(function(){
				$("#controls4").append($("<input type='text' name='website' class='text' size='30'/><br/>"));
			});
			/* $("#more11").click(function(){
				$("#controls1").remove($("<input type='text' name='tel' class='text' size='30'/>"+"<select name='type'><option value='work'>work</option><option value='home'>home</option></select><br/>"));
			});
			$("#more22").click(function(){
				$("#controls2").remove($("<input type='text' name='mail' class='text' size='30'/><br/>"));
			});
			$("#more33").click(function(){
				$("#controls3").remove($("<input type='text' name='im' class='text' size='30'/><br/>"));
			});
			$("#more44").click(function(){
				$("#controls4").remove($("<input type='text' name='website' class='text' size='30'/><br/>"));
			}); */
			$("#btn").click(function(){
				var username = $("#username").val();
				var job = $("#job").val();
				var company = $("#company").val();
				var address = $("#address").val();
				if(username == null || job==null || company==null || address==null){
					$("#error").html("姓名，微博，公司,地址不能为空");
					return;
				}else{
					$("#myform").submit();
				}
			});
		});
	</script>
</body>
</html>